package com.wxw.gulidemo.controller.front;/**
 * @author by xxz
 * @date 2022/6/14
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wxw.gulidemo.R;
import com.wxw.gulidemo.entity.EduCourse;
import com.wxw.gulidemo.entity.EduTeacher;
import com.wxw.gulidemo.service.IEduCourseService;
import com.wxw.gulidemo.service.IEduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;
import java.util.Base64;
import java.util.List;

/**
 * @Description

 * @author by xxz

 * @date 2022/6/14

 * @throws
 */
@RestController
@CrossOrigin
@RequestMapping("/eduService/indexFront")
public class IndexFrontController {

    /**
     * 查询最新前4条讲师数据
     * 查询最热前8条课程数据
     */

    @Autowired
    private IEduCourseService eduCourseService;

    @Autowired
    private IEduTeacherService eduTeacherService;

    //查询最新前4条讲师数据、最热前8条课程数据显示在前台首页
    @GetMapping("/index")
    public R index(){
        QueryWrapper<EduTeacher> wrapper1 = new QueryWrapper<>();
        wrapper1.orderByDesc("id");
        wrapper1.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(wrapper1);

        QueryWrapper<EduCourse> wrapper2 = new QueryWrapper<>();
        wrapper2.orderByDesc("view_count");
        wrapper2.last("limit 8");
        List<EduCourse> courseList = eduCourseService.list(wrapper2);
        return R.ok().data("teacherList",teacherList).data("courseList",courseList);
    }
}
